﻿<div class="row">
<?php foreach(array_reverse($this->getQuestions()) as $q): ?>
<div><div class="view">
Posted by <?php echo $this->getUser(Forum::model()->findByPk($q->question_id)->user_id) . " "; ?> on <?php echo Forum::model()->findByPk($q->question_id)->DateCreated . '<br/>'; ?>
<?php echo Forum::model()->findByPk($q->question_id)->Content; ?><br/>
<?php $id_for_answers = $q->question_id . '_answer'; ?>
<?php $id_for_answers_fields = $q->question_id . '_answer_fields'; ?>
<?php echo CHtml::link('Answer', '#/', array('onclick'=>'if($("#' . $id_for_answers .'").is(":visible")){$("#' . $id_for_answers . '").hide();} else{ $("#' . $id_for_answers . '").show(); }')); ?>&nbsp;
<?php if($this->getQuestionAnswers($q->question_id) > 0): ?>
<?php echo CHtml::link('Show', '#/', array('onclick'=>'if($("#' . $id_for_answers_fields .'").is(":visible")){$("#' . $id_for_answers_fields . '").hide();} else{ $("#' . $id_for_answers_fields . '").show(); }')); ?>
<?php endif; ?>&nbsp;
<?php if(Yii::app()->user->checkAccess('teacher')): ?>
<?php echo CHtml::link('Delete', '#/', array('submit'=>array('delete','id'=>$q->question_id, 'tid'=>$this->getTutorialId()),'confirm'=>'Are you sure you want to delete this question? All answers also will be deleted'));?> 
<?php endif; ?>&nbsp;
<?php if(Yii::app()->user->checkAccess('teacher')): ?>
<?php echo CHtml::link('Edit', '#/', array('submit'=>array('update','id'=>$q->question_id, 'tid'=>$this->getTutorialId())));?> 
<?php endif; ?>
</div>
<div id="<?php echo $id_for_answers_fields; ?>" <?php if($this->getQuestionCount() or $this->getQuestionAnswers($q->question_id) == 0 or $this->getQuestionAnswers($q->question_id) >= 7){echo 'hidden=""';} ?>>
<?php foreach($this->getQuestionAnswersContent($q->question_id) as $answer0): ?>
<div class="view" align="left" style="margin-left:50px" >
<?php echo ForumAnswers::model()->findByPk($answer0->answer_id)->Content; ?><br/>
<?php if(Yii::app()->user->checkAccess('teacher')): ?>
<?php echo CHtml::link('Delete', '#/', array('submit'=>array('deleteanswer','id'=>$answer0->answer_id, 'tid'=>$this->getTutorialId()),'confirm'=>'Are you sure you want to delete this answer?'));?> 
<?php endif; ?>&nbsp;
<?php if(Yii::app()->user->checkAccess('teacher')): ?>
<?php echo CHtml::link('Edit', '#/', array('submit'=>array('updateanswer','id'=>$answer0->answer_id, 'tid'=>$this->getTutorialId())));?> 
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
	<div id="<?php echo $id_for_answers; ?>" hidden="true" style="margin-left:320px">
		<?php 
			$answers = $this->getAnswers(); 
			$form = $this->beginWidget('CActiveForm', array(
		'id'=>'quick-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
			),
		'action'=>array('tutorials/createanswer', 'qid'=>$q->question_id, 'tid'=>$this->getTutorialId()),
		));
		
		echo $form->textarea($answers, 'Content');
		echo "<br/>";
		echo CHtml::submitButton($answers->isNewRecord ? 'Answer' : 'Answer');
		
		$this->endWidget();
		?>
	</div>
</div>
<?php endforeach; ?>
</div>
<div>
<?php /*$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
	'id'=>'edit-dialog',
	'options'=>array(
		'title'=>'Edit',
		'width'=>500,
		'height'=>300,
		'autoOpen'=>false,
	),
)); 
	$new_attendance = new Attendance;
	
	$form1 = $this->beginWidget('CActiveForm', array(
		'id'=>'quick-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
		),
		'action'=>array('tutorials/update'),
	));
	
		echo CHtml::submitButton($new_attendance->isNewRecord ? 'Create' : 'Create');
	
	
	$this->endWidget();
 $this->endWidget('zii.widgets.jui.CJuiDialog');*/ ?>
</div>
